package com.zyit.dao;

import com.zyit.DataObject.T_user;
import com.zyit.util.BeanRowMapper;
import com.zyit.util.DBHelp;

import java.util.List;

public class AdminDao {
    private DBHelp dbHelp = new DBHelp();
    public List<T_user> findListUser(String type) {
        String sql = "select id,account,nick_name,gender,type from t_user where type=?";
        return dbHelp.executeQueryForList(sql,new BeanRowMapper<>(T_user.class),type);
    }

    public T_user IdByUser(Integer id) {
      String sql = "select id,account,nick_name,password,gender,id_card_no,email,phone,type,open_id from t_user where id=?";
      return dbHelp.executeQueryForObject(sql,new BeanRowMapper<T_user>(T_user.class),id);
    }

    public void idUpdataUser(T_user tUser) {
        String sql = "update t_user set account = ?,nick_name = ?,id_card_no=?,email=?,phone=?,type=? where id = ?";
        dbHelp.executeUpdate(sql,tUser.getAccount(),tUser.getNick_name(),tUser.getId_card_no(),tUser.getEmail(),tUser.getPhone(),tUser.getType(),tUser.getId());

    }

    public void idDeleteUser(Integer i) {
        String sql = "delete from t_user where id = ?";
        dbHelp.executeUpdate(sql,i);
    }

    public void addUser(T_user tUser) {
        String sql = "insert into t_user(account,nick_name,password,id_card_no,email,phone) values(?,?,?,?,?,?)";
        dbHelp.executeUpdate(sql,tUser.getAccount(), tUser.getNick_name(), tUser.getPassword(), tUser.getId_card_no(), tUser.getEmail(), tUser.getPhone());
    }
}
